package com.jun.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jun.mapper.FoodMapper;
import com.jun.pojo.entity.Food;
import com.jun.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FoodServiceImpl extends ServiceImpl<FoodMapper, Food> implements FoodService {

  @Autowired
  private FoodMapper foodMapper;

  @Override
  public List<Food> foodList(int current, int size, String orderField, String orderType) {
    // 将当前页转换为偏移量
    int offset = (current - 1) * size;

    return foodMapper.foodList(offset, size, orderField, orderType);
  }

  @Override
  public List<Food> searchFoodList(String search) {
    return foodMapper.searchFoodList(search);
  }

  @Override
  public boolean hasLove(Integer foodId, Integer sysUserId) {
    int count = foodMapper.hasLove(foodId, sysUserId);
    return count == 1;
  }

  @Override
  public List<Food> selectAll(Integer userId) {
    return foodMapper.selectAll(userId);
  }
}

